<?php

class PagesController extends AppController
{

	var $name = 'Pages';
	var $helpers = array();
	var $uses = array();

	function display()
	{
	    if (! Auth::Check('register')) {
	        $this->redirect('/login');
	        exit();
	    }
        if (Auth::o()->is('client_admin')) {
    	    if (Auth::o()->is('active')) {
                if (Auth::o()->is('CANDIDATES')) {
                    $this->redirect('/candidates');
                    exit();
	            } elseif (Auth::o()->is('REPORTS') || Auth::o()->is('EMAIL_ON_REPORT')) {
                    $this->redirect('/reports');
                    exit();
	            } else {
                    $this->redirect('/help');
                    exit();
	            }
    	    } else {
                $this->redirect('/help');
                exit();
    	    }
        } elseif (Auth::o()->is('admin')) {
	        $this->redirect('/clients');
	        exit();
        }

		if (!func_num_args()) {
			$this->redirect('/');
		}
		$path = func_get_args();

		if (!count($path)) {
			$this->redirect('/');
		}
		$count = count($path);
		$page = null;
		$subpage = null;
		$title = null;

		if (!empty($path[0])) {
			$page = $path[0];
		}
		if (!empty($path[1])) {
			$subpage = $path[1];
		}
		if (!empty($path[$count - 1])) {
			$title = Inflector::humanize($path[$count - 1]);
		}
		$this->set('page', $page);
		$this->set('subpage', $subpage);
		$this->set('title', $title);
		$this->render(join('/', $path));
	}

}

?>